package com.zhiyou.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zhiyou.bean.Comment;
import com.zhiyou.bean.User;
import com.zhiyou.service.CommentService;
import com.zhiyou.util.Msg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping("/comment")
public class CommentController {

    @Autowired
    CommentService commentService;

    @RequestMapping("/getMyComment")
    @ResponseBody
    public Msg getMyComment(@RequestParam(value = "page",defaultValue = "1") int page,HttpSession session){
        System.out.println("===============");
        User user = (User) session.getAttribute("user");
        PageHelper.startPage(page,10);
        List<Comment> list = commentService.getMyComment(user.getId());
        PageInfo<Comment> commentPageInfo = new PageInfo<>(list, 5);
        return Msg.success().add("commentPageInfo",commentPageInfo);
    }

}
